package Lexico;

import TablaDeSimbolos.TablaDeSimbolos;

public class AlexicoActualizado {
	 TablaDeSimbolos tablaSimbolos;  
	  /** This character denotes the end of file */
	  public static final int YYEOF = -1;

	  /** initial size of the lookahead buffer */
	  private static final int ZZ_BUFFERSIZE = 16384;

	  /** lexical states */
	  public static final int ESTADO_COMENTARIO = 2;
	  public static final int ESTADO_STRING = 1;
	  public static final int YYINITIAL = 0;
	  public static final int ESTADO_COMENTARIO2 = 3;

	  /** 
	   * Translates characters to character classes
	   */
	  private static final String ZZ_CMAP_PACKED = 
	    "\11\0\1\6\1\5\2\0\1\4\22\0\1\7\1\0\1\62\1\64"+
	    "\1\51\2\0\1\53\1\57\1\60\1\21\1\13\1\14\1\13\1\10"+
	    "\1\22\12\2\1\15\1\14\1\17\1\20\1\16\2\0\1\32\2\50"+
	    "\1\34\1\12\1\50\1\1\1\45\3\1\1\46\1\1\1\33\1\35"+
	    "\1\1\1\1\1\36\1\44\1\37\3\1\1\40\2\1\1\55\1\63"+
	    "\1\56\1\54\1\3\1\0\1\23\2\1\1\25\1\11\2\1\1\42"+
	    "\3\1\1\43\1\1\1\24\1\26\2\1\1\27\1\41\1\31\3\1"+
	    "\1\30\2\1\1\61\1\47\1\52\uff82\0";

	  /** 
	   * Translates characters to character classes
	   */
	  private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);

	  /** 
	   * Translates DFA states to action switch labels.
	   */
	  private static final int [] ZZ_ACTION = zzUnpackAction();

	  private static final String ZZ_ACTION_PACKED_0 =
	    "\4\1\1\2\1\3\1\4\3\1\1\5\1\6\2\5"+
	    "\3\7\12\3\1\10\1\2\1\11\1\12\1\13\1\14"+
	    "\1\15\1\16\1\17\1\2\2\20\1\21\7\22\1\23"+
	    "\1\0\1\24\1\25\2\3\1\26\4\3\4\0\1\27"+
	    "\1\30\2\22\2\23\1\31\1\0\1\3\1\32\4\0"+
	    "\1\22\2\23\1\33\2\0\1\34\2\0\2\22\1\0"+
	    "\1\31\1\33\3\0\1\22\1\31\4\0\1\22\1\26"+
	    "\2\0";

	  private static int [] zzUnpackAction() {
	    int [] result = new int[103];
	    int offset = 0;
	    offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
	    return result;
	  }

	  private static int zzUnpackAction(String packed, int offset, int [] result) {
	    int i = 0;       /* index in packed string  */
	    int j = offset;  /* index in unpacked array */
	    int l = packed.length();
	    while (i < l) {
	      int count = packed.charAt(i++);
	      int value = packed.charAt(i++);
	      do result[j++] = value; while (--count > 0);
	    }
	    return j;
	  }


	  /** 
	   * Translates a state to a row index in the transition table
	   */
	  private static final int [] ZZ_ROWMAP = zzUnpackRowMap();

	  private static final String ZZ_ROWMAP_PACKED_0 =
	    "\0\0\0\65\0\152\0\237\0\324\0\u0109\0\u013e\0\u0173"+
	    "\0\324\0\u01a8\0\u01dd\0\324\0\324\0\u0212\0\u0247\0\u027c"+
	    "\0\324\0\u02b1\0\u02e6\0\u031b\0\u0350\0\u0385\0\u03ba\0\u03ef"+
	    "\0\u0424\0\u0459\0\u048e\0\u04c3\0\u04f8\0\324\0\324\0\324"+
	    "\0\u052d\0\324\0\324\0\324\0\u0562\0\u0597\0\u05cc\0\324"+
	    "\0\u0601\0\u0636\0\u066b\0\u06a0\0\u06d5\0\u070a\0\324\0\u073f"+
	    "\0\u0774\0\324\0\324\0\u07a9\0\u07de\0\u0109\0\u0813\0\u0848"+
	    "\0\u087d\0\u08b2\0\u08e7\0\u091c\0\u0951\0\u0986\0\324\0\u0562"+
	    "\0\u09bb\0\u09f0\0\u0a25\0\324\0\u0a5a\0\u0a8f\0\u0ac4\0\324"+
	    "\0\u0af9\0\u0b2e\0\u0b63\0\u0b98\0\u0bcd\0\u0c02\0\u0c37\0\u0c6c"+
	    "\0\u0c6c\0\u0ca1\0\324\0\u0cd6\0\u0d0b\0\u0d40\0\u0d75\0\u0c02"+
	    "\0\u0daa\0\u0ddf\0\u0e14\0\u0e49\0\u0e7e\0\u0eb3\0\u0ee8\0\u0f1d"+
	    "\0\u0f52\0\u0f87\0\u0fbc\0\u0ff1\0\324\0\u1026\0\u105b";

	  private static int [] zzUnpackRowMap() {
	    int [] result = new int[103];
	    int offset = 0;
	    offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
	    return result;
	  }

	  private static int zzUnpackRowMap(String packed, int offset, int [] result) {
	    int i = 0;  /* index in packed string  */
	    int j = offset;  /* index in unpacked array */
	    int l = packed.length();
	    while (i < l) {
	      int high = packed.charAt(i++) << 16;
	      result[j++] = high | packed.charAt(i++);
	    }
	    return j;
	  }

	  /** 
	   * The transition table of the DFA
	   */
	  private static final int [] ZZ_TRANS = zzUnpackTrans();

	  private static final String ZZ_TRANS_PACKED_0 =
	    "\1\5\1\6\1\7\1\5\1\10\2\11\1\12\1\13"+
	    "\2\6\1\14\1\15\1\16\1\17\1\20\1\21\2\14"+
	    "\1\22\1\23\1\6\1\24\1\6\1\25\1\6\1\26"+
	    "\1\27\1\6\1\30\2\6\1\31\1\32\2\6\1\33"+
	    "\2\6\1\5\1\6\1\34\1\5\1\35\1\36\1\37"+
	    "\1\40\1\41\1\42\1\43\1\44\1\5\1\45\53\46"+
	    "\1\47\6\46\1\50\1\5\1\46\2\51\1\52\47\51"+
	    "\1\11\1\53\11\51\21\54\1\55\31\54\1\56\4\54"+
	    "\1\57\4\54\66\0\3\6\5\0\2\6\10\0\24\6"+
	    "\1\0\1\6\15\0\1\60\1\7\5\0\1\61\2\60"+
	    "\10\0\24\60\1\0\1\60\21\0\1\11\66\0\1\12"+
	    "\135\0\1\40\24\0\1\62\64\0\1\63\62\0\1\63"+
	    "\1\0\1\63\45\0\3\6\5\0\2\6\10\0\1\6"+
	    "\1\64\22\6\1\0\1\6\15\0\3\6\5\0\2\6"+
	    "\10\0\3\6\1\65\20\6\1\0\1\6\15\0\3\6"+
	    "\5\0\2\6\10\0\4\6\1\66\17\6\1\0\1\6"+
	    "\15\0\3\6\5\0\2\6\10\0\3\6\1\24\20\6"+
	    "\1\0\1\6\15\0\3\6\5\0\2\6\10\0\10\6"+
	    "\1\67\13\6\1\0\1\6\15\0\3\6\5\0\2\6"+
	    "\10\0\12\6\1\70\11\6\1\0\1\6\15\0\3\6"+
	    "\5\0\2\6\10\0\13\6\1\66\10\6\1\0\1\6"+
	    "\15\0\3\6\5\0\2\6\10\0\12\6\1\30\11\6"+
	    "\1\0\1\6\15\0\3\6\5\0\2\6\10\0\17\6"+
	    "\1\71\4\6\1\0\1\6\15\0\3\6\5\0\2\6"+
	    "\10\0\22\6\1\72\1\6\1\0\1\6\16\0\1\34"+
	    "\7\0\1\34\17\0\1\34\1\0\1\34\13\0\1\34"+
	    "\14\0\1\73\1\74\1\75\1\73\3\0\2\73\2\74"+
	    "\10\73\21\74\1\76\2\74\1\73\1\74\14\73\10\0"+
	    "\1\37\10\0\1\77\45\0\1\100\62\0\62\46\2\0"+
	    "\63\46\2\73\1\46\52\51\1\0\13\51\1\101\1\52"+
	    "\5\51\1\102\2\101\10\51\24\101\1\51\1\101\1\51"+
	    "\1\0\64\51\1\73\12\51\21\54\1\0\36\54\1\0"+
	    "\4\54\60\0\1\11\4\0\21\54\1\73\36\54\1\73"+
	    "\4\54\1\0\3\103\5\0\2\103\10\0\24\103\1\0"+
	    "\1\103\1\0\1\104\14\0\1\105\6\0\2\106\53\0"+
	    "\3\6\5\0\2\6\10\0\2\6\1\66\21\6\1\0"+
	    "\1\6\15\0\3\6\5\0\2\6\10\0\6\6\1\66"+
	    "\15\6\1\0\1\6\15\0\3\6\5\0\2\6\10\0"+
	    "\11\6\1\66\12\6\1\0\1\6\15\0\3\6\5\0"+
	    "\2\6\10\0\14\6\1\66\7\6\1\0\1\6\15\0"+
	    "\3\6\5\0\2\6\10\0\20\6\1\66\3\6\1\0"+
	    "\1\6\15\0\3\6\5\0\2\6\10\0\13\6\1\66"+
	    "\7\6\1\107\1\0\1\6\67\0\1\110\12\0\3\111"+
	    "\5\0\2\111\10\0\24\111\1\0\1\111\2\0\1\110"+
	    "\13\0\1\112\5\0\1\113\42\0\1\110\12\0\3\111"+
	    "\5\0\2\111\10\0\22\111\1\114\1\111\1\0\1\111"+
	    "\2\0\1\110\11\0\52\51\1\104\14\51\1\115\47\51"+
	    "\1\0\12\51\1\0\3\103\5\0\2\103\10\0\24\103"+
	    "\1\0\1\103\15\0\1\116\1\105\6\0\2\117\10\0"+
	    "\24\116\1\0\1\116\16\0\1\120\10\0\1\121\52\0"+
	    "\3\6\5\0\2\6\10\0\24\6\1\122\1\6\15\0"+
	    "\3\111\5\0\2\111\10\0\24\111\1\0\1\111\2\0"+
	    "\1\123\13\0\1\112\5\0\1\113\42\0\1\123\13\0"+
	    "\1\124\63\0\3\111\5\0\2\111\10\0\23\111\1\125"+
	    "\1\0\1\111\2\0\1\123\11\0\1\51\1\126\1\115"+
	    "\6\51\2\127\10\51\24\126\1\51\1\126\1\51\1\0"+
	    "\12\51\1\0\3\130\5\0\2\130\10\0\24\130\1\0"+
	    "\1\130\1\0\1\104\13\0\1\130\1\131\1\130\5\0"+
	    "\2\130\1\132\7\0\24\130\1\0\1\130\1\0\1\104"+
	    "\14\0\1\120\123\0\1\133\25\0\1\124\6\0\2\134"+
	    "\40\0\1\123\12\0\3\111\5\0\2\111\10\0\24\111"+
	    "\1\135\1\111\2\0\1\123\11\0\1\51\3\126\5\51"+
	    "\2\126\10\51\24\126\1\51\1\126\1\51\1\104\13\51"+
	    "\3\126\5\51\2\126\1\136\7\51\24\126\1\51\1\126"+
	    "\1\51\1\104\12\51\1\0\1\116\1\131\1\130\5\0"+
	    "\2\116\10\0\24\116\1\0\1\116\1\0\1\104\14\0"+
	    "\1\137\124\0\1\140\24\0\1\141\10\0\1\142\112\0"+
	    "\1\143\23\0\2\51\1\144\47\51\1\0\12\51\1\0"+
	    "\1\116\1\137\6\0\2\116\10\0\24\116\1\0\1\116"+
	    "\43\0\1\145\37\0\1\141\50\0\1\123\13\0\1\141"+
	    "\124\0\1\146\22\0\1\51\1\126\1\144\6\51\2\126"+
	    "\10\51\24\126\1\51\1\126\1\51\1\0\12\51\27\0"+
	    "\1\147\110\0\1\123\11\0";

	  private static int [] zzUnpackTrans() {
	    int [] result = new int[4240];
	    int offset = 0;
	    offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
	    return result;
	  }

	  private static int zzUnpackTrans(String packed, int offset, int [] result) {
	    int i = 0;       /* index in packed string  */
	    int j = offset;  /* index in unpacked array */
	    int l = packed.length();
	    while (i < l) {
	      int count = packed.charAt(i++);
	      int value = packed.charAt(i++);
	      value--;
	      do result[j++] = value; while (--count > 0);
	    }
	    return j;
	  }


	  /* error codes */
	  private static final int ZZ_UNKNOWN_ERROR = 0;
	  private static final int ZZ_NO_MATCH = 1;
	  private static final int ZZ_PUSHBACK_2BIG = 2;

	  /* error messages for the codes above */
	  private static final String ZZ_ERROR_MSG[] = {
	    "Unkown internal scanner error",
	    "Error: could not match input",
	    "Error: pushback value was too large"
	  };

	  /**
	   * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
	   */
	  private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();

	  private static final String ZZ_ATTRIBUTE_PACKED_0 =
	    "\4\1\1\11\3\1\1\11\2\1\2\11\3\1\1\11"+
	    "\14\1\3\11\1\1\3\11\3\1\1\11\6\1\1\11"+
	    "\1\1\1\0\2\11\7\1\4\0\1\11\4\1\1\11"+
	    "\1\1\1\0\1\1\1\11\4\0\4\1\2\0\1\11"+
	    "\2\0\2\1\1\0\2\1\3\0\2\1\4\0\1\1"+
	    "\1\11\2\0";

	  private static int [] zzUnpackAttribute() {
	    int [] result = new int[103];
	    int offset = 0;
	    offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
	    return result;
	  }

	  private static int zzUnpackAttribute(String packed, int offset, int [] result) {
	    int i = 0;       /* index in packed string  */
	    int j = offset;  /* index in unpacked array */
	    int l = packed.length();
	    while (i < l) {
	      int count = packed.charAt(i++);
	      int value = packed.charAt(i++);
	      do result[j++] = value; while (--count > 0);
	    }
	    return j;
	  }

	  /** the input device */
	  private java.io.Reader zzReader;

	  /** the current state of the DFA */
	  private int zzState;

	  /** the current lexical state */
	  private int zzLexicalState = YYINITIAL;

	  /** this buffer contains the current text to be matched and is
	      the source of the yytext() string */
	  private char zzBuffer[] = new char[ZZ_BUFFERSIZE];

	  /** the textposition at the last accepting state */
	  private int zzMarkedPos;

	  /** the textposition at the last state to be included in yytext */
	  private int zzPushbackPos;

	  /** the current text position in the buffer */
	  private int zzCurrentPos;

	  /** startRead marks the beginning of the yytext() string in the buffer */
	  private int zzStartRead;

	  /** endRead marks the last character in the buffer, that has been read
	      from input */
	  private int zzEndRead;

	  /** number of newlines encountered up to the start of the matched text */
	  private int yyline;

	  /** the number of characters up to the start of the matched text */
	  private int yychar;

	  /**
	   * the number of characters from the last newline up to the start of the 
	   * matched text
	   */
	  private int yycolumn;

	  /** 
	   * zzAtBOL == true <=> the scanner is currently at the beginning of a line
	   */
	  private boolean zzAtBOL = true;

	  /** zzAtEOF == true <=> the scanner is at the EOF */
	  private boolean zzAtEOF;

	  /* user code: */
	  private int comment_count = 0;
		StringBuffer string = new StringBuffer();
		
		private void escribirTraza(String tipoToken,int linea,String contenido){
			System.out.println("Token: \""+contenido+"\"    "+tipoToken+" Linea: "+ linea);
		}
		
		private Token generaToken(String tipoToken,Object contenido ,int linea){
			Object atributos;
			if(tipoToken=="PUNT" || tipoToken=="OP_COMP" || tipoToken=="OP_MAT" || tipoToken=="OP_LOG" ||tipoToken=="STRING"){
				atributos=(String)contenido;
			}
			else{
				if(tipoToken.equals("IDENTIFICADOR" )){
					atributos = tablaSimbolos.getReservada((String)contenido);
					if(atributos == null){
						atributos=tablaSimbolos.insertaIdentificador((String)contenido);
						escribirTraza("IDENTIFICADOR",yyline+1,yytext()); 
					}
					else{tipoToken = "PAL_RES";escribirTraza("PAL_RES",yyline+1,yytext()); }
				}
				else{
					if(tipoToken=="IDENTIFICADOR" ){
						atributos=tablaSimbolos.insertaIdentificador((String)contenido);//.insertaTabla((String)contenido);
					}
					else{
						if(tipoToken=="INTEGER"){
							atributos=(Integer)contenido;
						}
						else{
							if(tipoToken=="REAL" ){
								atributos=(Float)contenido;
							}
							else{
								if(tipoToken=="CHAR" ){
									atributos=(Character)contenido;
								}
								else{
									//si es abre/cierra parentesis, asignacion,op_punt, corchetes, no tiene atrib 
									atributos=null;
								}
							}
						}
					}
				}
			}
			return (new Token(tipoToken,atributos,linea));
		}

	  /**
	   * Creates a new scanner
	   * There is also a java.io.InputStream version of this constructor.
	   *
	   * @param   in  the java.io.Reader to read input from.
	   */
	  public AlexicoActualizado(java.io.Reader in,TablaDeSimbolos t) {
	    this.zzReader = in;
	    this.tablaSimbolos=t;
	  }

	  /**
	   * Creates a new scanner.
	   * There is also java.io.Reader version of this constructor.
	   *
	   * @param   in  the java.io.Inputstream to read input from.
	   */
	  AlexicoActualizado(java.io.InputStream in,TablaDeSimbolos t) {
	    this(new java.io.InputStreamReader(in),t);
	  }


	  /** 
	   * Unpacks the compressed character translation table.
	   *
	   * @param packed   the packed character translation table
	   * @return         the unpacked character translation table
	   */
	  private static char [] zzUnpackCMap(String packed) {
	    char [] map = new char[0x10000];
	    int i = 0;  /* index in packed string  */
	    int j = 0;  /* index in unpacked array */
	    while (i < 152) {
	      int  count = packed.charAt(i++);
	      char value = packed.charAt(i++);
	      do map[j++] = value; while (--count > 0);
	    }
	    return map;
	  }


	  /**
	   * Refills the input buffer.
	   *
	   * @return      <code>false</code>, iff there was new input.
	   * 
	   * @exception   java.io.IOException  if any I/O-Error occurs
	   */
	  private boolean zzRefill() throws java.io.IOException {

	    /* first: make room (if you can) */
	    if (zzStartRead > 0) {
	      System.arraycopy(zzBuffer, zzStartRead,
	                       zzBuffer, 0,
	                       zzEndRead-zzStartRead);

	      /* translate stored positions */
	      zzEndRead-= zzStartRead;
	      zzCurrentPos-= zzStartRead;
	      zzMarkedPos-= zzStartRead;
	      zzPushbackPos-= zzStartRead;
	      zzStartRead = 0;
	    }

	    /* is the buffer big enough? */
	    if (zzCurrentPos >= zzBuffer.length) {
	      /* if not: blow it up */
	      char newBuffer[] = new char[zzCurrentPos*2];
	      System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
	      zzBuffer = newBuffer;
	    }

	    /* finally: fill the buffer with new input */
	    int numRead = zzReader.read(zzBuffer, zzEndRead,
	                                            zzBuffer.length-zzEndRead);

	    if (numRead < 0) {
	      return true;
	    }
	    else {
	      zzEndRead+= numRead;
	      return false;
	    }
	  }

	    
	  /**
	   * Closes the input stream.
	   */
	  public final void yyclose() throws java.io.IOException {
	    zzAtEOF = true;            /* indicate end of file */
	    zzEndRead = zzStartRead;  /* invalidate buffer    */

	    if (zzReader != null)
	      zzReader.close();
	  }


	  /**
	   * Resets the scanner to read from a new input stream.
	   * Does not close the old reader.
	   *
	   * All internal variables are reset, the old input stream 
	   * <b>cannot</b> be reused (internal buffer is discarded and lost).
	   * Lexical state is set to <tt>ZZ_INITIAL</tt>.
	   *
	   * @param reader   the new input stream 
	   */
	  public final void yyreset(java.io.Reader reader) {
	    zzReader = reader;
	    zzAtBOL  = true;
	    zzAtEOF  = false;
	    zzEndRead = zzStartRead = 0;
	    zzCurrentPos = zzMarkedPos = zzPushbackPos = 0;
	    yyline = yychar = yycolumn = 0;
	    zzLexicalState = YYINITIAL;
	  }


	  /**
	   * Returns the current lexical state.
	   */
	  public final int yystate() {
	    return zzLexicalState;
	  }


	  /**
	   * Enters a new lexical state
	   *
	   * @param newState the new lexical state
	   */
	  public final void yybegin(int newState) {
	    zzLexicalState = newState;
	  }


	  /**
	   * Returns the text matched by the current regular expression.
	   */
	  public final String yytext() {
	    return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
	  }


	  /**
	   * Returns the character at position <tt>pos</tt> from the 
	   * matched text. 
	   * 
	   * It is equivalent to yytext().charAt(pos), but faster
	   *
	   * @param pos the position of the character to fetch. 
	   *            A value from 0 to yylength()-1.
	   *
	   * @return the character at position pos
	   */
	  public final char yycharat(int pos) {
	    return zzBuffer[zzStartRead+pos];
	  }


	  /**
	   * Returns the length of the matched text region.
	   */
	  public final int yylength() {
	    return zzMarkedPos-zzStartRead;
	  }


	  /**
	   * Reports an error that occured while scanning.
	   *
	   * In a wellformed scanner (no or only correct usage of 
	   * yypushback(int) and a match-all fallback rule) this method 
	   * will only be called with things that "Can't Possibly Happen".
	   * If this method is called, something is seriously wrong
	   * (e.g. a JFlex bug producing a faulty scanner etc.).
	   *
	   * Usual syntax/scanner level error handling should be done
	   * in error fallback rules.
	   *
	   * @param   errorCode  the code of the errormessage to display
	   */
	  private void zzScanError(int errorCode) {
	    String message;
	    try {
	      message = ZZ_ERROR_MSG[errorCode];
	    }
	    catch (ArrayIndexOutOfBoundsException e) {
	      message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
	    }

	    throw new Error(message);
	  } 


	  /**
	   * Pushes the specified amount of characters back into the input stream.
	   *
	   * They will be read again by then next call of the scanning method
	   *
	   * @param number  the number of characters to be read again.
	   *                This number must not be greater than yylength()!
	   */
	  public void yypushback(int number)  {
	    if ( number > yylength() )
	      zzScanError(ZZ_PUSHBACK_2BIG);

	    zzMarkedPos -= number;
	  }


	  /**
	   * Resumes scanning until the next regular expression is matched,
	   * the end of input is encountered or an I/O-Error occurs.
	   *
	   * @return      the next token
	   * @exception   java.io.IOException  if any I/O-Error occurs
	   */
	  public Token siguiente_token() throws java.io.IOException,ExcepcionLexico {
	    int zzInput;
	    int zzAction;

	    // cached fields:
	    int zzCurrentPosL;
	    int zzMarkedPosL;
	    int zzEndReadL = zzEndRead;
	    char [] zzBufferL = zzBuffer;
	    char [] zzCMapL = ZZ_CMAP;

	    int [] zzTransL = ZZ_TRANS;
	    int [] zzRowMapL = ZZ_ROWMAP;
	    int [] zzAttrL = ZZ_ATTRIBUTE;

	    while (true) {
	      zzMarkedPosL = zzMarkedPos;

	      yychar+= zzMarkedPosL-zzStartRead;

	      boolean zzR = false;
	      for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL;
	                                                             zzCurrentPosL++) {
	        switch (zzBufferL[zzCurrentPosL]) {
	        case '\u000B':
	        case '\u000C':
	        case '\u0085':
	        case '\u2028':
	        case '\u2029':
	          yyline++;
	          zzR = false;
	          break;
	        case '\r':
	          yyline++;
	          zzR = true;
	          break;
	        case '\n':
	          if (zzR)
	            zzR = false;
	          else {
	            yyline++;
	          }
	          break;
	        default:
	          zzR = false;
	        }
	      }

	      if (zzR) {
	        // peek one character ahead if it is \n (if we have counted one line too much)
	        boolean zzPeek;
	        if (zzMarkedPosL < zzEndReadL)
	          zzPeek = zzBufferL[zzMarkedPosL] == '\n';
	        else if (zzAtEOF)
	          zzPeek = false;
	        else {
	          boolean eof = zzRefill();
	          zzEndReadL = zzEndRead;
	          zzMarkedPosL = zzMarkedPos;
	          zzBufferL = zzBuffer;
	          if (eof) 
	            zzPeek = false;
	          else 
	            zzPeek = zzBufferL[zzMarkedPosL] == '\n';
	        }
	        if (zzPeek) yyline--;
	      }
	      zzAction = -1;

	      zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
	  
	      zzState = zzLexicalState;


	      zzForAction: {
	        while (true) {
	    
	          if (zzCurrentPosL < zzEndReadL)
	            zzInput = zzBufferL[zzCurrentPosL++];
	          else if (zzAtEOF) {
	            zzInput = YYEOF;
	            break zzForAction;
	          }
	          else {
	            // store back cached positions
	            zzCurrentPos  = zzCurrentPosL;
	            zzMarkedPos   = zzMarkedPosL;
	            boolean eof = zzRefill();
	            // get translated positions and possibly new buffer
	            zzCurrentPosL  = zzCurrentPos;
	            zzMarkedPosL   = zzMarkedPos;
	            zzBufferL      = zzBuffer;
	            zzEndReadL     = zzEndRead;
	            if (eof) {
	              zzInput = YYEOF;
	              break zzForAction;
	            }
	            else {
	              zzInput = zzBufferL[zzCurrentPosL++];
	            }
	          }
	          int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
	          if (zzNext == -1) break zzForAction;
	          zzState = zzNext;

	          int zzAttributes = zzAttrL[zzState];
	          if ( (zzAttributes & 1) == 1 ) {
	            zzAction = zzState;
	            zzMarkedPosL = zzCurrentPosL;
	            if ( (zzAttributes & 8) == 8 ) break zzForAction;
	          }

	        }
	      }

	      // store back cached position
	      zzMarkedPos = zzMarkedPosL;

	      switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
	        case 19: 
	          { System.out.println("Error encontrado: identificador mal formado");
		yybegin(YYINITIAL);
		throw new ExcepcionLexico(yyline+1,1);
	          }
	        case 29: break;
	        case 5: 
	          { escribirTraza("PUNT",yyline+1,yytext());
		yybegin(YYINITIAL);
		return generaToken("PUNT",new String(yytext()), yyline+1);
	          }
	        case 30: break;
	        case 4: 
	          { escribirTraza("ENTERO",yyline+1,yytext());
		yybegin(YYINITIAL);
		Integer aux= new Integer(Integer.valueOf(yytext()));
		return generaToken("INTEGER",aux,yyline+1);
	          }
	        case 31: break;
	        case 17: 
	          { yybegin(YYINITIAL);
		  	 	 System.out.println("He encontrado un String " + string.toString());
				 return generaToken("STRING",string.toString(),yyline+1);
	          }
	        case 32: break;
	        case 12: 
	          { escribirTraza("ABRE_PAREN",yyline+1,yytext());
			return (generaToken("ABRE_PAREN",null,yyline+1));
	          }
	        case 33: break;
	        case 16: 
	          { string.append( yytext() );
	          }
	        case 34: break;
	        case 15: 
	          { string.setLength(0); yybegin(ESTADO_STRING);
	          }
	        case 35: break;
	        case 26: 
	          { escribirTraza("CHAR",yyline+1,yytext());
		yybegin(YYINITIAL);
		return generaToken("CHAR",new Character(yytext().charAt(1)),yyline+1);
	          }
	        case 36: break;
	        case 8: 
	          { escribirTraza("ENTERO",yyline+1,yytext());


		/*realizar la conversion del texto a hexadecimal*/
	            String auxiliar=yytext();
	            auxiliar=auxiliar.substring(1);//quitamos el "$"
	            int traduccionHex=0;
	            int numBase=1;//iremos guardando aqui las potencias de 16
	            char c;int j;
	            for(int i=0;i<auxiliar.length();i++){
	                c=auxiliar.charAt(auxiliar.length()-i-1);
	                j =Character.digit(c,16);
	                traduccionHex+=j*numBase;
	                numBase=numBase*16;
	            }
	        //System.out.println("Valor: "+traduccionHex);
		return generaToken("INTEGER",new Integer(traduccionHex),yyline+1);
	          }
	        case 37: break;
	        case 27: 
	          { System.out.println("Error encontrado: Real mal formado");
		yybegin(YYINITIAL);
		throw new ExcepcionLexico(yyline+1,4);
	          }
	        case 38: break;
	        case 1: 
	          { yybegin(YYINITIAL);
	          }
	        case 39: break;
	        case 11: 
	          { escribirTraza("CIERRA_CORCHETE",yyline+1,yytext());
			return (generaToken("CIERRA_CORCHETE",null,yyline+1));
	          }
	        case 40: break;
	        case 22: 
	          { escribirTraza("OP_LOG",yyline+1,yytext());	
		yybegin(YYINITIAL);
		return generaToken("OP_LOG",new String(yytext()), yyline+1);
	          }
	        case 41: break;
	        case 14: 
	          { yybegin(ESTADO_COMENTARIO);
	          }
	        case 42: break;
	        case 10: 
	          { escribirTraza("ABRE_CORCHETE",yyline+1,yytext());
			return (generaToken("ABRE_CORCHETE",null,yyline+1));
	          }
	        case 43: break;
	        case 13: 
	          { escribirTraza("CIERRA_PAREN",yyline+1,yytext());
			return (generaToken("CIERRA_PAREN",null,yyline+1));
	          }
	        case 44: break;
	        case 25: 
	          { escribirTraza("REAL",yyline+1,yytext());
		yybegin(YYINITIAL);
		Float aux1=new Float(Float.valueOf(yytext()));
		return generaToken("REAL",aux1,yyline+1);
	          }
	        case 45: break;
	        case 28: 
	          { System.out.println("Error encontrado: Caracter mal formado");
		yybegin(YYINITIAL);
		throw new ExcepcionLexico(yyline+1,2);
	          }
	        case 46: break;
	        case 3: 
	          { yybegin(YYINITIAL);
		return generaToken("IDENTIFICADOR",new String(yytext()), yyline+1);
	          }
	        case 47: break;
	        case 20: 
	          { escribirTraza("OP_ASIG",yyline+1,yytext());
			return (generaToken("OP_ASIG",null,yyline+1));
	          }
	        case 48: break;
	        case 23: 
	          { yybegin(ESTADO_COMENTARIO2);
	          }
	        case 49: break;
	        case 21: 
	          { escribirTraza("OP_COMP",yyline+1,yytext());
			return generaToken("OP_COMP",new String(yytext()), yyline+1);
	          }
	        case 50: break;
	        case 7: 
	          { escribirTraza("OP_COMP",yyline+1,yytext());
		yybegin(YYINITIAL);
		return generaToken("OP_COMP",new String(yytext()), yyline+1);
	          }
	        case 51: break;
	        case 9: 
	          { escribirTraza("OP_PUNT",yyline+1,yytext());
			return generaToken ("OP_PUNT",null,yyline+1);
	          }
	        case 52: break;
	        case 2: 
	          { System.out.println("Error encontrado: no se esperaba el caracter");
		yybegin(YYINITIAL);
		throw new ExcepcionLexico(yyline+1,3);
	          }
	        case 53: break;
	        case 24: 
	          { yybegin(YYINITIAL);
		String k=yytext();
		k=k.substring(1);//quitamos el primer elemento(#)
		Integer aux=Integer.parseInt(k);
	      char c= (char )aux.intValue();
		//k=k.valueOf(c);
		Character aux2 = new Character(c);
		if(aux.intValue()>127){
	            System.out.println("caracter mal formado: valor superior a 127");
	            throw new ExcepcionLexico(yyline+1,2);//error de caracter mal formado.
	        }
	      else{
			escribirTraza("CHAR",yyline+1,yytext());
			return generaToken("CHAR",aux2,yyline+1);
		}
	          }
	        case 54: break;
	        case 6: 
	          { escribirTraza("OP_MAT",yyline+1,yytext());
		yybegin(YYINITIAL);
		return generaToken("OP_MAT",new String(yytext()), yyline+1);
	          }
	        case 55: break;
	        case 18: 
	          { 
	          }
	        case 56: break;
	        default: 
	          if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
	            zzAtEOF = true;
	              {
	                System.out.println("Fin fichero");
		return (new Token("EOF",yytext(),yyline+1));
	              }
	          } 
	          else {
	            zzScanError(ZZ_NO_MATCH);
	          }
	      }
	    }
	  }
}
